package com.sushe.service;

import com.sushe.dao.BedAssignmentDao;
import com.sushe.dao.RoomDao;
import com.sushe.dao.StudentQueryDao;
import com.sushe.service.jiekou.BedAssignmentService;
import com.sushe.service.jiekou.StudentQueryService;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class StudentQueryServiceImpl implements StudentQueryService {

    private BedAssignmentDao bedAssignmentDao = new BedAssignmentDao();
    private RoomDao roomDao = new RoomDao();
    private StudentQueryDao studentQueryDao = new StudentQueryDao();


    @Override
    public  void queryStudentByRoom() throws SQLException, ClassNotFoundException {
        Scanner sc = new Scanner(System.in);
        //输入宿舍楼并判断是否存在
        System.out.println("请输入宿舍楼栋编号Id：");
        Integer  buildingId = sc.nextInt();
        //判断该楼栋编号是否存在，不存在则报错并返回结束方法
        String buildingName= bedAssignmentDao.selectByBuildingId(buildingId);
        System.out.println("楼栋名称为："+buildingName);
        if(buildingName== null){
            System.out.println("该楼栋不存在");
            return;
        }

        //用户输入房间号判断是否存在
        System.out.println("请输入宿舍房间号：");
        String roomNumber=sc.next();
        //判断房间是否存在
        Integer roomId= roomDao.selectByRoomNumberAndBuildingId(roomNumber,buildingId);
        if(roomId==null){
            System.out.println("该房间不存在");
            return;
        }

        //执行查询
        List<String> studentNameList=studentQueryDao.queryStudentNameByRoomId(roomId);
        System.out.println("该房间的入住学生有：");
        System.out.println(Arrays.toString(studentNameList.toArray()));
    }
}
